################################################################################
##
##   Hack Title:		easyUCP Map_Mod add on
##   
##   Hack Author:		AmigaLink < Amiga@ms25.de >  
##			
##			
##			
##
##   Installation Level:	Easy 
##   Installation Time:		3 Minutes 
##
##   Files To Edit:		3
##
##				\includes\usercp_register.php
##
##				\templates\subSilver\easyucp_body.tpl
##				\templates\subSilver\profile_add_body.tpl
##
################################################################################
##
##  This hack is released under the GPL License. 
##
################################################################################
#
#----------[ PLEASE NOTE ]------------------------------
#
# Skip or reinstall the \includes\usercp_register.php and \templates\subSilver\profile_add_body.tpl
# parts in the original Map_Mod installation guide!

#
#----------[ OPEN ]-------------------------------------
#

\includes\usercp_register.php

#
#----------[ FIND ]-------------------------------------
#

	$strip_var_list = array('username' => 'username', 'email' => 'email', 'icq' => 'icq', 'aim' => 'aim', 'msn' => 'msn', 'yim' => 'yim', 'website' => 'website', 'location' => 'location', 'occupation' => 'occupation', 'interests' => 'interests');

#
#----------[ AFTER, ADD ]-------------------------------
#

// Begin Map Mod
$strip_vars_mapmod = array('longitude' => 'longitude', 'latitude' => 'latitude');
$strip_var_list = array_merge ($strip_var_list, $strip_vars_mapmod);
// End Map Mod

#
#----------[ FIND ]-------------------------------------
#

	$user_avatar_type = ( empty($user_avatar_loc) && $mode == 'editprofile' ) ? $userdata['user_avatar_type'] : '';

#
#----------[ AFTER, ADD ]-------------------------------
#

// Begin Map Mod
$longitude = ( !empty($HTTP_POST_VARS['longitude']) ) ? str_replace(',','.',trim(strip_tags( $HTTP_POST_VARS['longitude'] ) ) ) : '';
$latitude = ( !empty($HTTP_POST_VARS['latitude']) ) ? str_replace(',','.',trim(strip_tags( $HTTP_POST_VARS['latitude'] ) ) ) : '';
// End Map Mod

#
#----------[ FIND ]-------------------------------------
#

			}
// Preferences

#
#----------[ BEFORE, ADD ]------------------------------
#

			// Begin Map Mod
			$sql = "SELECT user_id
				FROM ". MAP_MOD_USER_TABLE . "
				WHERE user_id = $user_id ";
			if (! $result = $db->sql_query($sql)) {
				message_die(GENERAL_ERROR, 'Could not get map data.', '', __LINE__, __FILE__, $sql);
			}
			$row = $db->sql_fetchrow($result);
			if ($row['user_id']==$user_id) {
				$sql = "DELETE 
					FROM " . MAP_MOD_USER_TABLE . "
					WHERE user_id = $user_id ";
				if (! $result = $db->sql_query($sql)) {
					message_die(GENERAL_ERROR, 'Could not delete map data.', '', __LINE__, __FILE__, $sql);
				}
			}
			if (((float)$longitude != 0.0) || ((float)$latitude != 0.0)) {
				$sql = "INSERT INTO " .MAP_MOD_USER_TABLE. "
				VALUES (" . intval($user_id) . ", " . (float)$longitude . "," . (float)$latitude. ")";
				if(! $result = $db->sql_query($sql)) {
					message_die(GENERAL_ERROR, 'Could not update map table.', '', __LINE__, __FILE__, $sql);
				}
			}
			// End Map Mod

#
#----------[ FIND ]-------------------------------------
#

			if ( !($result = $db->sql_query($sql, BEGIN_TRANSACTION)) )
			{
				message_die(GENERAL_ERROR, 'Could not insert data into users table', '', __LINE__, __FILE__, $sql);
			}

#
#----------[ AFTER, ADD ]-------------------------------
#

			// Begin Map Mod
			if (((float)$longitude != 0.0) || ((float)$latitude != 0.0)) {
				$sql = "INSERT INTO " . MAP_MOD_USER_TABLE . " (user_id, longitude, latitude)
					VALUES (" . intval($user_id) . ", " . (float)$longitude . "," . (float)$latitude . ")";
				if(! $result = $db->sql_query($sql))
				{
					message_die(GENERAL_ERROR, 'Could not update map table.', '', __LINE__, __FILE__, $sql);
				}
			}
			// End Map Mod
#
#----------[ FIND ]-------------------------------------
#

}

//
// Default pages
//

#
#----------[ BEFORE, ADD ]------------------------------
#

// Begin Map Mod
$sql = "SELECT * 
	FROM " . MAP_MOD_USER_TABLE . " 
	WHERE user_id=".$userdata['user_id'];
if(!$result = $db->sql_query($sql))
{
	message_die(GENERAL_ERROR, "Couldn't obtain map information.", "", __LINE__, __FILE__, $sql);
}
$row = $db->sql_fetchrow($result);
$longitude = $row['longitude'];
$latitude = $row['latitude'];
// End Map Mod

#
#----------[ FIND ]-------------------------------------
#

		'L_EMAIL_ADDRESS' => $lang['Email_address'],

#
#----------[ AFTER, ADD ]-------------------------------
#

// Begin Map Mod
		'LONGITUDE' => $longitude,
		'LATITUDE' => $latitude,
		'L_LONGITUDE' => $lang['map_longitude'],
		'L_LATITUDE' => $lang['map_latitude'],
		'L_LONGITUDE_HELP' => $lang['map_longitudehelp'],
		'L_LATITUDE_HELP' => $lang['map_latitudehelp'],
		'L_MAP_INFO' => $lang['map_section_title'],
		'L_MAP_DESCRIPTION' => $lang['map_section_description'],
		'L_DEGREES' => $lang['map_degrees'],
		'L_MINUTES' => $lang['map_minutes'],
		'L_FIND_PLACE' => $lang['map_find_place'],
		'U_FIND_PLACE' => append_sid("map_search.$phpEx"),
// End Map Mod

#
#----------[ OPEN ]-------------------------------------
#

\templates\subSilver\easyucp_body.tpl

#
#----------[ FIND ]-------------------------------------
#

							<td><b><span class="gen">{LOCATION}</span></b></td>

#
#----------[ REPLACE WITH ]-----------------------------
#

<!-- BEGIN switch_user_map -->
							<td><b><span class="gen">{LOCATION}</span></b><br /><a href="{U_USER_MAP}" class="genmed">{L_USER_MAP}</a></td>
<!-- END switch_user_map -->
<!-- BEGIN switch_user_no_map -->
							<td><b><span class="gen">{LOCATION}</span></b></td>
<!-- END switch_user_no_map -->

#
#----------[ OPEN ]-------------------------------------
#

\templates\subSilver\profile_add_body.tpl

#
#----------[ FIND ]-------------------------------------
#

	<!-- END switch_ucp_signature -->

#
#----------[ AFTER, ADD ]-------------------------------
#

	<!-- BEGIN switch_ucp_info -->
<!-- Begin Map Mod -->
<tr>
	<th class="thHead" colspan="2" height="25" valign="middle"><a name="map">{L_MAP_INFO}</a></th>
</tr>
<tr>
	<td class="row1" colspan="2"><span class="gensmall">{L_MAP_DESCRIPTION}</span></td>
</tr>
<tr>
	<td class="row1"><span class="gen">{L_LONGITUDE}{L_LONGITUDE_HELP}:</span></td>
	<td class="row2">
	<input type="text" class="post" style="width: 150px"  name="longitude" size="10" maxlength="10" value="{LONGITUDE}" /> <span class="gen">{L_DEGREES}</span>&nbsp;&nbsp;
	<input type="submit" name="placesubmit" value="{L_FIND_PLACE}" class="liteoption" onClick="window.open('{U_FIND_PLACE}', '_phpbbsearch', 'HEIGHT=250,resizable=yes,WIDTH=400');return false;" /></span>
	</td>
</tr>
<tr>
	<td class="row1"><span class="gen">{L_LATITUDE}{L_LATITUDE_HELP}:</span></td>
	<td class="row2">
	<input type="text" class="post" style="width: 150px"  name="latitude" size="10" maxlength="10" value="{LATITUDE}" /> <span class="gen">{L_DEGREES}</span>
	</td>
</tr>
<!-- End Map Mod -->
	<!-- END switch_ucp_info -->

#
#----------[ SAVE AND CLOSE ALL FILES ]-----------------
#
#     EoM
#